/************
 * 创建组件
 * Created by donkey on 2018/5/17
 ************/

// import qs from 'qs'

export default {
    // extends:uiUpload,
    name: 'uploaderComp',
    props: {
        title: {
            type: String,
            required: true
        },
        url: {
            type: String
        },
        delUrl: {
            type: String
        },
        params: {
            type: Object
        },
        headerData: {
            type: Object
        },
        accept: {
            type: String
        },
        rename: {
            type: String
        },
        width: {
            type: String,
            default: '1000'
        },
        height: {
            type: String,
            default: '500'
        },
        callback: {
            type: Object
        },
        uploadNumber : Number,
        fileSize : {
            type : [String , Number]
        },
        imageWidth : [String,Number],
        imageHeight : [String,Number],
    },
    template: `
            <el-dialog
            v-if="dialogTableVisible"
            ref="uploadDialog"
            :title="title"
            :visible="true"
            :close-on-press-escape="false"
            :close-on-click-modal="false"
            :before-close="closeFn"
            :width="width+'px'"
            >
                <div class="ui flex column of-a" :style="{height:height+'px'}">
                    <ui-uploader
                        ref="uiUpload"
                        :fileSize="fileSize"
                        :uploadNumber="uploadNumber"
                        :url="url"
                        :rename="rename"
                        :delUrl="delUrl"
                        :headerData="headerData"
                        :accept="accept"
                        :params="params"
                        :imageWidth = "imageWidth"
                        :imageHeight = "imageHeight"
                    />
                </div>
            </el-dialog>`,
    data() {
        return {
            dialogTableVisible: true
        }
    },
    /*computed:{
        para() {
            return qs.stringify(this.params);
        }
    },*/
    methods: {
        closeFn(done) {
            const uploader = this.$refs.uiUpload.$children[0]

            // this.dialogTableVisible = false //使用v-if删除会出现多余的空注释, 不晓得是什么原因

            this.$emit('uploader_closed') //换成触发事件删除

            if (uploader.started) { //判断点击过上传按钮就需要执行回调
                this.callback.success()
            }
            done()
        }
    }
}
;

